<?php
/**
 * 团队历史成绩
 */
apf_require_controller("Abstract");
apf_require_class("Bll_Jx_Setting");
apf_require_class("Bll_Jx_Relation");
apf_require_class("Bll_Jx_Plan");
class Team_QueryTeamHistoryController extends AbstractController {

    public function handle_request() {
        $params = $this->request->get_parameters();
        $this->setting_bll = new Bll_Jx_Setting();
        $this->team_bll  = new Bll_Jx_Relation();

        $params['year'] = empty($params['year']) ? date('Y') : $params['year'];
        $last_month = $this->setting_bll->format_performance();
        $params['month'] =  empty($params['month']) ? substr($last_month[1],4) : $params['month'];

        $year_kp = $this->setting_bll->get_performance_month($params['year']);

        if(empty($params['reviewYear'])){
            $ckdate = $params['year'].$params['month'];
        }else{
            $ckdate = $params['reviewYear'].$params['reviewMonth'];
        }
//echo $ckdate;
        //取自己的下属
        //tp($year_kp);
        $uid = $this->request->get_user_id();
        $sublist = $this->team_bll->get_lower_user($uid);
        $_where = array();
        if(!empty($sublist)){
            $uids = array();
            foreach($sublist as $val){
                $uids[] = $val['user_id'];
            }
            $_where[" userId IN(".implode(',', $uids).") AND 1=?"] = 1;
            $_where['serachMonth'] = $ckdate;
            $plan_bll = new Bll_Jx_Plan();
            $tmp_plan_data = $plan_bll->find_performance($_where);
            if(!empty($tmp_plan_data)){
                $plan_data = array();
                foreach($tmp_plan_data as $val){
                    $plan_data[$val['userId']] = $val;
                }
                foreach ($sublist as $k=> $val){
                    $sublist[$k]['score'] = $plan_data[$val['user_id']];
                }
            }
        }

        //tp($sublist);
        $this->request->set_attribute('ckdate',$ckdate);
        $this->request->set_attribute('sublist',$sublist);
        $this->request->set_attribute('year_kp',$year_kp);
        $this->request->set_attribute('params',$params);
        return 'Team_QueryTeamHistory';
    }
}